<#import "../tpl/pageTep.ftl" as page>
<@page.pageBase currentMenu="积分商城">
<style>
  .form-horizontal .controls {
    line-height: 40px;
    height: 40px;
    margin-left: 3px;
  }
</style>
  <form id="searchForm" class="form-panel" action="${basepath}/rest/manage/voucherconvert/selectVoucherConvertPage">
    <ul class="panel-content">
      <li>
        <div class="control-group span5">
          <div class="search-controls  controls">
            <input type="text" name="userName" id="userName" value="" placeholder="搜索关键字">
          </div>
        </div>
        <div class="form-actions span2">
          <button type="submit" class="button  button-primary">
            搜索
          </button>
        </div>
      </li>
    </ul>
  </form>
    <div id="grid"></div>
<script>
  var Grid = BUI.Grid,
    Store = BUI.Data.Store,
    columns = [
      {title: '序号', dataIndex: 'id', elCls: 'center', width: '10%'},
      {title: '礼券名称', dataIndex: 'voucherName', elCls: 'center', width: '20%'},
      {title: '兑换人', dataIndex: 'userName', elCls: 'center', width: '20%'},
      {title: '兑换数量', dataIndex: 'amount', elCls: 'center', width: '10%'},
      {title: '兑换积分', dataIndex: 'voucherScore', elCls: 'center', width: '10%'},
      {title: '兑换时间', dataIndex: 'createTime', elCls: 'center', width: '15%'},
      {
        title: '操作', dataIndex: 'id', elCls: 'center', width: '15%', renderer: function (value) {
          return '<a href="javascript:deleteOne(' + value + ')">删除</a>';
        }
      }
    ];

  var store = new Store({
      url: '/rest/manage/voucherconvert/selectVoucherConvertPage',
      autoLoad: true, //自动加载数据
      params: { //配置初始请求的参数
        length: '10',
        status: $("#status").val()
      },
      pageSize: 10,	// 配置分页数目
      root: 'list',
      totalProperty: 'total'
    }),
    grid = new Grid.Grid({
      render: '#grid',
      columns: columns,
      loadMask: true, //加载数据时显示屏蔽层
      store: store,
      plugins: [Grid.Plugins.CheckSelection], // 插件形式引入多选表格
      // 底部工具栏
      bbar: {
        pagingBar: true
      }
    });

  grid.render();
  /*--------------------------------模糊查询---------------------------------------------*/
  var form = new BUI.Form.HForm({
    srcNode: '#searchForm'
  }).render();

  form.on('beforesubmit', function (ev) {
    //序列化成对象
    var obj = form.serializeToObject();
    obj.start = 0; //返回第一页
    store.load(obj);
    return false;
  });
  /*--------------------------------模糊查询---------------------------------------------*/
  //删除单个用户
  function deleteOne(value) {
    BUI.Message.Confirm('确认要删除吗？', function () {
      $.ajax({
        type: 'POST',
        url: '${basepath}/rest/manage/voucherconvert/deleteJson',
        dataType: 'json',
        data: {
          id: value
        },
        success: function () {
          var obj = form.serializeToObject();
          obj.start = 0; //返回第一页
          store.load(obj);
        }
      });
    }, 'question');
  }
</script>

</@page.pageBase>
